//外接订单   运维（零担）


interface IOperationManagentBreakBulkViewModel extends ng.IScope {
    //备注
    remark:string;
    modalRemark:string;

    /**
     * 承运单详情
     */
    CData: invoiceManagement;
    /**
     * 订单列表
     */
    orderDataList: Array<invoiceManagementOrder>;
    /**
      * 查看详情事件
      */
    orderDetail: (item: invoiceManagementOrder) => void;
    /**
     * 合同信息
     */
    contractData: invoiceManagementContract;
    /**
     * 费用信息列表
     */
    orderCostList: Array<invoiceManagementFee>;
    /**
     * 承运单id
     */
    id: string;
    /**
     * 修改承运商
     */
    carrierEdit: () => void;
    /**
     * 保存承运商
     */
    saveCarrier: () => void;
    /**
     * 修改车辆信息
     */
    carEdit: () => void;
    /**
     * 保存车辆信息
     */
    saveCar: () => void;
    /**
     * 修改应付价格信息
     */
    receivalbleEdit: () => void;
    /**
     * 保存应付价格信息
     */
    saveReceivalble: () => void;


    /**
     * 修改合同信息
     */
    contractEdit: () => void;
    /**
     * 保存合同信息
     */
    saveContract: () => void;
    /**
     * 修改承运商附件信息
     */
    attachmentEdit: () => void;
    /**
     * 保存承运商附件信息
     */
    saveAttachment: () => void;

    /**
     * 取消承运商附件信息
     */
    cancelSaveAttachment: () => void;

    /**
     * 承运商类型下拉
     */
    carrierTypeDropDown: ValueListItemResponse[];

    /**
     * 车型下拉
     */
    carTypeDropDown: ValueListItemResponse[];
    /**
     * 车长下拉
     */
    carLengthDropDown: ValueListItemResponse[];


    /**
     * 合同货物数量单位下拉
     */
    contractNumDropDown: ValueListItemResponse[];
    /**
     * 油卡状态下拉
     */
    oilStatusDropDown: ValueListItemResponse[];


    /**
     * 应付单价单位下拉
     */
    priceUnitDropDown: ValueListItemResponse[];
    /**
     * 付款方式
     */
    paymentMethodDropDown: ValueListItemResponse[];

    /**
     * 驾驶证上传组件
     */
    driverUploader: any;
    /**
     * 挂车证上传组件
     */
    trailerUploader: any;
    /**
     * 行驶证上传组件
     */
    travelUploader: any;
    /**
     * 身份证上传组件
     */
    idCardUploader: any;
    /**
     * 车辆照片
     */
    carPicUploader: any;
    /**
     * 道路运输证
     */
    roadTransportCardUploader:any
    /**
     * 道路运输经营许可证
     */
    roadTransportLicenseUploader:any;
    /**
     * 从业资格证
     */
    occupationalLicenseUploader:any;
    /**
     * 磅单照片
     */
    weightNoteUploader:any;
    /**
      * 订单数据
      */
    orderData: invoiceManagementOrder;
    /**
     * 总线路列表
     */
    orderTotalList: Array<invoiceManagementOrder>;
    /**
     * 总线路查看详情事件
     */
    orderTotalData: (item: invoiceManagementOrder) => void;
    /**
     * 子线路数据
     */
    orderChildData: Array<invoiceManagementOrderChild>;
    /**
     * 子线路列表
     */
    orderChildList: Array<invoiceManagementOrderChild>;
    /**
    * 子线路查看详情事件
    */
    orderChildDetail: (item: invoiceManagementOrderChild) => void;
    /**
    * 子线路查看详情数据
    */
    orderChildDataDetail: invoiceManagementOrderChild;
    /**
    * app竞价
    */
    orderAppBiddingList: Array<quotationResponse>;
    /**
    * 订单附件
    */
    orderUploader: any;
    /**
    * 回单附件
    */
    loaderInfoList: any;

    /**
     * 返回事件
     */
    skipManage: () => void;

    /**
     * 承运商自动提示消息
     */
    searchCarrier(value: string): any;
    /**
     * 选中承运商自动填充数据
     */
    carrierSelect(select: angucomplete<CarrierListItemResponse>): void;

    /**
     * 承运商车辆自动提示消息
     */
    searchCar(value: string): any;
    /**
     * 选中车牌号自动填充数据
     */
    carCodeSelect(select: angucomplete<CarListItemResponse>): void;

    /**
     * 银行卡自动提示消息
     */
    searchBank(value: string): any;
    /**
     * 选中银行卡自动填充数据
     */
    bankCodeSelect(select: angucomplete<BankListItemResponse>): void;
    /**
     * 获取银行卡名称
     */
    getBankName: () => void;

    /**
     * 驾驶证上传组件
     */
    driverBoxUploader: any;
    /**
     * 挂车证上传组件
     */
    trailerBoxUploader: any;
    /**
     * 行驶证上传组件
     */
    travelBoxUploader: any;
    /**
     * 身份证上传组件
     */
    idCardBoxUploader: any;
    /**
     * 车辆照片
     */
    carPicBoxUploader: any;
    /**
     * 道路运输证
     */
    roadTransportCardUploaderBox:any
    /**
     * 道路运输经营许可证
     */
    roadTransportLicenseUploaderBox:any;
    /**
     * 从业资格证
     */
    occupationalLicenseUploaderBox:any;
    /**
     * 磅单照片
     */
    weightNoteUploaderBox:any


    contractDIs: boolean;
    /**
     * 修改承运商 按钮的隐藏/显示
     */
    carryOrderIsShow: boolean;
    /**
     * 修改车辆信息 按钮的隐藏/显示
     */
    carInfoIsShow: boolean;
    /**
     * 修改应付价格 按钮的隐藏/显示
     */
    receivableIsShow: boolean;
    /**
     * 修改合同信息 按钮的隐藏/显示
     */
    contractIsShow: boolean;
    /**
     * 修改附件 按钮的隐藏/显示 
     */
    attachmentIsShow: boolean;

    receiptDis: boolean;
    /**
     * 开户银行 禁用
     */
    openBankDis: boolean;

    //弹窗中的承运商信息
    /**
     * 承运商号码
     */
    carrierPhoneBox: string;
    /**
     * 承运商类型
     */
    carrierTypeEnumBox: string;

    /** 
     * 道路运输许可证号
    */
    permitNumber: string;
     /**
     * 所属辖区市列表
     */
    deliverCityList: any;
    /**
     * 所属辖区区列表
     */
    deliverAreaList: any;
    /** 
     * 所属辖区(省)
    */
    countrySubdivisionProvinceCode: string;
    /** 
     * 所属辖区(市)
    */
    countrySubdivisionCityCode: string;
    /** 
     * 所属辖区(区)
    */
    countrySubdivisionCountryCode: string;
    /** 
     * 道路运输证字号
    */
    roadTransportCertificateNumber: string;
    /**
     * 所属辖区code
     */
    countrySubdivisionCode: string;
     /** 
     * 道路运输许可证号
    */
    permitNumberBox: string;
     /** 
     * 道路运输证字号
    */
    roadTransportCertificateNumberBox: string;
    /**
     * 所属辖区
     */
    countrySubdivisionValue: string;
    //弹窗中的车辆信息
    /**
     * 驾驶员姓名
     */
    driverNameBox: string;
    /**
     * 驾驶员号码
     */
    driverPhoneBox: string;
    /**
     * 车长
     */
    carLengthEnumBox: string;
    /**
     * 车型
     */
    carTypeEnumBox: string;


    //弹窗中的应付信息
    /**
     * 应付单价 
     */
    payablePriceBox: number;
    /**
     * 应付说明
     */
    payableSummaryBox: string;
    /**
     * 回单款
     */
    receiptPriceBox: number;
    /**
     * 开户银行
     */
    bankNameBox: string;
    /**
     * 持卡人姓名
     */
    holderBox: string;
    /**
     * 回单款单位
     */
    receiptPriceUnitEnumBox: string;
    /**
     * 应付单价单位
     */
    payablePriceUnitEnumBox: string;
    /**
     * 预付款1
     */
    advancePriceOne: string;
    /**
     * 预付款方式1
     */
    advancePriceTypeOne: string;
    /**
     * 预付款2
     */
    advancePriceTwo: string;
    /**
     * 预付款方式2
     */
    advancePriceTypeTwo: string;



    //弹窗中的合同信息
    /**
     * 合同号
     */
    contractNumberT: string;
    /**
     * 合同货物数量
     */
    quantityOfGoodsT: number;
    /**
     * 合同货物数量单位
     */
    goodsUnitEnumT: string;
    /**
     * 油卡卡号
     */
    oilCardNumberT: string;
    /**
     * 油卡状态
     */
    oilCardStatusEnumT: string;
    /**
     * 驾驶证号
     */
    driverLicenseNumberT: string;
    /**
     * 车架号
     */
    frameNumberT: string;
    /**
     * 挂车号
     */
    trailerNumberT: string;
    /**
     * 发动机号
     */
    engineNumberT: string;
    /**
     * 备用电话
     */
    altermatePhoneT: string;
    /**
     * 辅助工具(需回收)
     */
    auxiliaryToolT: string;
    /**
     * 挂车车架号
     */
    trailerFrameNumberT: string;
    /**
     * 运费总价
     */
    totalPriceT:number;
    /**
     * 银行卡
     */
    bankCode: string;

    /**
     * 车辆信息
     */
    carBox: string;

    /**
     * 车牌号
     */
    carCodeBox: string;
    /**
     * 车辆id
     */
    carIdBox: string;

    saveReceivalbleDis: boolean;

      /**
     * 点击图片时候触发，用以旋转放大图片
     */
    handleImgClick:(item:any)=>void;
    /**
     * 用以旋转放大的图片的路径
     */
    selectedImgSrc:string;

    attachList:OssUploaderItem[];
    attachList2:OssUploaderItem[];
}


class IOperationController_breakBulk {
    /**
     * 附件地址
     */
    baseImageUrl: string;
    //附件
    uploaderList: AddCarAttachmentDetail[] = [];
    //弹框中的附件
    uploaderArr: AddCarAttachmentDetail[] = [];
    //订单附件（详情）
    orderUploaderArr: AddCarAttachmentDetail[] = [];

    //回单附件
    attachmentUploader: AddCarAttachmentDetail[] = [];


    constructor(private $scope: IOperationManagentBreakBulkViewModel, private operationService: IOperationService, private orderService: IorderService, private $location: ng.ILocationService,
        private $ngBootbox: BootboxService, private $state: angular.ui.IStateService, private routeService: routeService,  private feeService: IFeeService,
        private $http: ng.IHttpService, private authorizationService: IAuthorizationService, private valueService: IValueService, private carrierService: ICarrierService, private carService: ICarService,
        private commonService: commonService, private $timeout: ng.ITimeoutService, private areaService: IAreaService,private ossUploaderService:ossUploaderService) {
        this.baseImageUrl = this.routeService.getBaseUrl() + "attachment/";
        this.init();
    }

    /**
     * 初始化
     */
    init(): void {
        this.$scope.id = this.$location.search().id;

        this.loadData();
        this.$scope.contractDIs = true;

        this.$scope.carryOrderIsShow = false;
        this.$scope.carInfoIsShow = false;
        this.$scope.receivableIsShow = false;
        this.$scope.contractIsShow = false;
        this.$scope.attachmentIsShow = false;
        this.$scope.receiptDis = true;
        this.$scope.openBankDis = true;

        // this.$scope.saveReceivalble = this.saveReceivalble;

        this.authorizationService.auth("5E1F9989AA5F596D06429E0D93616A47ACE03F2B9F7C90D35FD5A057D3AF3782").then((res) => {
            this.$scope.carryOrderIsShow = res.data.extData;
        });

        this.authorizationService.auth("5E1F9989AA5F596D06429E0D93616A478B4FACDCAEB73F46").then((res) => {
            this.$scope.carInfoIsShow = res.data.extData;
        });

        this.authorizationService.auth("5E1F9989AA5F596D06429E0D93616A47A84CECFF3A17D6A862506D4A1091DAB9").then((res) => {
            this.$scope.receivableIsShow = res.data.extData;
        });
        this.authorizationService.auth("5E1F9989AA5F596D06429E0D93616A478CBCA692368F067B5CA4D24B245211A6").then((res) => {
            this.$scope.contractIsShow = res.data.extData;
        });
        this.authorizationService.auth("5E1F9989AA5F596D06429E0D93616A47340EFD81C08E9D28A3C18E92E2705152").then((res) => {
            this.$scope.attachmentIsShow = res.data.extData;
        });

        this.attachmentsCar();
        this.$scope.handleImgClick=(item)=>{this.$scope.selectedImgSrc=item.imgSrc;}
    }

    /**
     * 弹窗中修改附件
     */
    attachmentsCar = () => {
       
        const OssFile = this.ossUploaderService.getOssFile();
        // 修改附件
        this.$scope.attachList2=[
            {
                title:'驾驶证',
                uploader:null,
                uploaderName:'driverUploader2'
            },{
                title:'挂车证',
                uploader:null,
                uploaderName:'trailerUploader2'
            },{
                title:'行驶证',
                uploader:null,
                uploaderName:'travelUploader2'
            },{
                title:'身份证',
                uploader:null,
                uploaderName:'idCardUploader2'
            },{
                title:'车辆照片',
                uploader:null,
                uploaderName:'carPicUploader2'
            },{
                title:'道路运输证',
                uploader:null,
                uploaderName:'roadTransportCardUploader2'
            },{
                title:'道路运输经营许可证',
                uploader:null,
                uploaderName:'roadTransportLicenseUploader2'
            },{
                title:'从业资格证',
                uploader:null,
                uploaderName:'occupationalLicenseUploader2'
            },{
                title:'磅单照片',
                uploader:null,
                uploaderName:'weightNoteUploader2'
            },
        ]

        this.$scope.attachList2.forEach((attach,index)=>{
            attach.uploader=new OssFile(this.$scope,attach.uploader,{uploaderList:this.uploaderList,tag:index+1});
            attach.uploader.onSuccess=(item)=>{this.onSuccessItem(item.fileName,item.imgSrc,index+1,item._file)};
            attach.uploader.onDelete=(item)=>{
                attach.uploader.queue=attach.uploader.queue.filter(it=>item.fileName!=it.fileName&&item.imgSrc!=it.imgSrc);
                this.uploaderList=this.uploaderList.filter(it=>attach.uploader.tag!=it.attachmentTag)
            }
        })


    }

    /**
     * 获取市区下拉
     */
    getProvinceList = () => {
        this.areaService.getCity(this.$scope.countrySubdivisionProvinceCode).then(res => {
            this.$scope.deliverCityList = res.data.data;

        });
        this.areaService.getCounty(this.$scope.countrySubdivisionCityCode).then(res => {
            this.$scope.deliverAreaList = res.data.data;
        });
    }

    /**
     * 加载数据
     */
    loadData = () => {
      

           // 详情中的附件
        this.$scope.attachList=[
            {
                title:'驾驶证',
                uploader:null,
                uploaderName:'driverUploader'
            },{
                title:'挂车证',
                uploader:null,
                uploaderName:'trailerUploader'
            },{
                title:'行驶证',
                uploader:null,
                uploaderName:'travelUploader'
            },{
                title:'身份证',
                uploader:null,
                uploaderName:'idCardUploader'
            },{
                title:'车辆照片',
                uploader:null,
                uploaderName:'carPicUploader'
            },{
                title:'道路运输证',
                uploader:null,
                uploaderName:'roadTransportCardUploader'
            },{
                title:'道路运输经营许可证',
                uploader:null,
                uploaderName:'roadTransportLicenseUploader'
            },{
                title:'从业资格证',
                uploader:null,
                uploaderName:'occupationalLicenseUploader'
            },{
                title:'磅单照片',
                uploader:null,
                uploaderName:'weightNoteUploader'
            },
        ]
        const OssFile = this.ossUploaderService.getOssFile();
        this.$scope.attachList.forEach((attach,index)=>{
            attach.uploader=new OssFile(this.$scope,attach.uploader,{uploaderList:[],tag:index+1});
           
        })

         //订单附件
        
         this.$scope.orderUploader = new OssFile(this.$scope,this.$scope.orderUploader,{uploaderList:[],tag:1,multiple:true});
       
     

        this.orderService.invoiceManagementDetail(this.$scope.id).then((res) => {
            //获取承运单数据
            this.$scope.CData = res.data;
            //获取订单列表
            this.$scope.orderDataList = res.data.orderList;
            //订单列表——查看详情
            this.$scope.orderDetail = this.showOrderDetailDialog;
            //合同信息
            this.$scope.contractData = res.data.contract;

            //12.1新增 备注
            this.$scope.remark = res.data.remarks;

            if (res.data.contract) {
                this.$scope.contractDIs = false;
                $("#contractTime").val(res.data.contract.contractTime);
            }

            //付款信息——费用信息
            this.$scope.orderCostList = res.data.feeList;

            //修改承运商
            this.$scope.carrierEdit = this.carrierEdit;

            //修改车辆信息
            this.$scope.carEdit = this.carEdit;
            //获取车辆信息
            this.carService.getDetail(this.$scope.CData.carId).then((res) => {
                if (res.data.driver == null || res.data.driver == "0") {
                    res.data.driver = " ";
                }
                let car = res.data.carCode + " " + res.data.driver + " " + res.data.driverPhone;
                this.$scope.carBox = car;
                this.$scope.permitNumber = res.data.permitNumber;
                this.$scope.countrySubdivisionCode = res.data.countrySubdivisionCode;
                this.$scope.roadTransportCertificateNumber = res.data.roadTransportCertificateNumber;
            });

            this.$scope.permitNumber = res.data.permitNumber;
            let countrySubdivisionValue;
            this.$scope.countrySubdivisionValue = res.data.countrySubdivisionProvince + res.data.countrySubdivisionCity + res.data.countrySubdivisionCountry
            this.$scope.roadTransportCertificateNumber = res.data.roadTransportCertificateNumber;


            //修改应付价格信息
            this.$scope.receivalbleEdit = this.receivalbleEdit;

            //修改合同信息
            this.$scope.contractEdit = this.contractEdit;

            //修改承运商附件信息
            this.$scope.attachmentEdit = this.attachmentEdit;
            /**
             * 承运单附件
             */
            this.carrierAttachment();

            //加载回单附件
            this.getReceiptAttchment(res.data.orderList);

            //返回事件
            this.$scope.skipManage = this.skipManage;

        });

    }

    /**
     * 承运单附件
     */
    carrierAttachment = () => {
        this.$scope.attachList.forEach(attach=>{
            attach.uploader.clearQueue();
        })
        this.uploaderList = [];
        this.uploaderArr = [];
        let carArr = this.$scope.CData.carrierOrderAttachments;
        carArr.forEach((item, index) => {
            this.uploaderList.push(item);
            this.uploaderArr.push(item);
            this.$scope.attachList[Number(item.attachmentTag)-1].uploader.addByAttach(item);

            
        });
    }

    /**
    * 回单附件
    */
    getReceiptAttchment = (data: invoiceManagementOrder[]) => {
        this.$scope.loaderInfoList = [];
        const OssFile=this.ossUploaderService.getOssFile();
        data.forEach((item, index) => {
            let orderReceiptAttachList:OssUploaderItem[] = [];


            var loadC = [];
            item.childList.forEach((itemC, indeC) => {
                orderReceiptAttachList.push(
                    {
                        title:'回单'+(indeC+1),
                        uploader:null,
                        uploaderName: 'receipt' + indeC+'Uploader'
                    }
                )
                orderReceiptAttachList[indeC].uploader=new  OssFile(this.$scope,orderReceiptAttachList[indeC].uploader,{uploaderList:[],tag:index+1,multiple:true});

          

                itemC.receiptAttachments.forEach((itemR, indexR) => {
                    this.uploaderList.push(itemR);
                    this.uploaderArr.push(itemR);
                    orderReceiptAttachList[indeC].uploader.addByAttach(itemR)
                });
            });
            this.$scope.loaderInfoList.push(orderReceiptAttachList);
        });
    };


    /**
     * 返回事件
     */
    skipManage = () => {
        this.$state.go("app.opera.operation_manage", { name: "argument" });
    }


    /**
     * 订单列表——查看详情
     */
    showOrderDetailDialog = (item: invoiceManagementOrder) => {
        /**
        * 获取订单数据（总单数据）
        */
        this.$scope.orderData = item;
        /**
         * 查看总线路详情详情事件
         */
        this.$scope.orderTotalData = this.showOrderTotalData;
        /**
         * 总线路列表
         */
        this.$scope.orderTotalList = [item];
        /**
         * 子线路数据
         */
        this.$scope.orderChildData = item.childList;
        /**
         * 子线路列表
         */
        this.$scope.orderChildList = item.childList;
        /**
         * 子线路查看详情事件
         */
        this.$scope.orderChildDetail = this.showOrderChildDetail;
        /**
         * app竞价
         */
        this.orderService.quotation(item.id).then((res) => {
            this.$scope.orderAppBiddingList = res.data.data;
        });

      
       
        /**
         * 订单附件
         */
        this.orderUploaderArr = [];
        let orderArr = item.orderAttachments;
        this.$scope.orderUploader.clearQueue();
        orderArr.forEach((itemO, index) => {
            this.uploaderArr.push(itemO);
            this.orderUploaderArr.push(itemO);
            // this.commonService.showFileItem(itemO, this.$scope.orderUploader);
            this.$scope.orderUploader.addByAttach(itemO)
        });

    }

    /**
     * 总线路 查看详情事件
     */
    showOrderTotalData = (item: invoiceManagementOrder) => {
        this.$scope.orderData = item;
    }
    /**
    * 子线路 查看详情事件
    */
    showOrderChildDetail = (item: invoiceManagementOrderChild) => {
        /**
         * 获取子线路详情数据
         */
        this.$scope.orderChildDataDetail = item;
    }


    /**
     * 修改承运商
     */
    carrierEdit = () => {

        this.$scope.carrierTypeEnumBox = this.$scope.CData.carrierTypeEnum;
        this.$scope.carrierPhoneBox = this.$scope.CData.carrierPhone;
        this.$scope.carrierTypeDropDown = this.valueService.getCarrierTypeList().data;
        /**
         * 承运商输入提示
         */
        this.$scope.searchCarrier = this.searchCarrier;
        this.$scope.carrierSelect = this.carrierSelect;

        $("#carrierName_value").val(this.$scope.CData.carrier);
        this.$scope.saveCarrier = this.saveCarrier;
    }
    //保存承运商修改
    saveCarrier = () => {
        this.operationService.getCarrierList("", null, $("#carrierName_value").val(), "", "", "", "", "", true, 0, 5).then((res) => {
            if (res.data.data.length == 0) {
                this.$ngBootbox.alert("承运商非法,请重新填写");
                return;
            } else {
                this.operationService.updateCarrier(this.$scope.id, $("#carrierName_value").val(), this.$scope.CData.carrierId, this.$scope.carrierPhoneBox,
                    this.$scope.carrierTypeEnumBox).then((result) => {
                        this.$ngBootbox.alert("修改成功");
                        $('#CarrierAdd').modal('hide');
                        this.loadData();
                    });
            }
        });
    }

    /**
     * 自动填充承运商信息
     */
    searchCarrier = (value: string) => {
        return this.operationService.getCarrierList("", null, value, "", "", "", "", "", true, 0, 5).then((res) => {
            return res.data.data;
        });
    }

    /**
     * 承运商自动填充信息
     */
    carrierSelect = (select: angucomplete<CarrierListItemResponse>) => {
        if (select) {
            this.$scope.CData.carrierId = select.description.id;
            this.$scope.carrierPhoneBox = select.description.phone;
            this.operationService.getCarrierDetail(select.description.id).then((res) => {
                this.$scope.carrierTypeEnumBox = res.data.type;
            });
        }
    }





    /**
     * 修改车辆信息
     */
    carEdit = () => {
        this.$scope.driverNameBox = this.$scope.CData.driver;
        this.$scope.driverPhoneBox = this.$scope.CData.driverPhone;
        this.$scope.carCodeBox = this.$scope.CData.carCode;
        this.$scope.carLengthEnumBox = this.$scope.CData.carLengthEnum;
        this.$scope.carTypeEnumBox = this.$scope.CData.vehicleTypeEnum;

        this.$scope.carIdBox = this.$scope.CData.carId;
        this.$scope.permitNumberBox = this.$scope.CData.permitNumber;
        this.$scope.countrySubdivisionCode = this.$scope.CData.countrySubdivisionCode;
        this.$scope.roadTransportCertificateNumberBox = this.$scope.CData.roadTransportCertificateNumber;

        this.$scope.countrySubdivisionProvinceCode = this.$scope.CData.countrySubdivisionProvinceCode;
        this.$scope.countrySubdivisionCityCode = this.$scope.CData.countrySubdivisionCityCode;
        this.$scope.countrySubdivisionCountryCode = this.$scope.CData.countrySubdivisionCountryCode;
        this.getProvinceList();
        this.$scope.carTypeDropDown = this.valueService.getCarTypeList().data;
        this.$scope.carLengthDropDown = this.valueService.getCarLengthList().data;
        /**
         * 承运商车辆输入提示
         */
        this.$scope.searchCar = this.searchCar;
        this.$scope.carCodeSelect = this.carCodeSelect;

        if (!$("#carForm").valid()) { return };
        $('#carsAdd_driverNameBox').removeClass('error');
        $('#carTypeEnumBox').removeClass('error');
        $('#carLengthEnumBox').removeClass('error');


        this.carService.getDetail(this.$scope.carIdBox).then((res) => {
            if (res.data.driver == null || res.data.driver == "0") {
                res.data.driver = " ";
            }
            let car = res.data.carCode + " " + res.data.driver + " " + res.data.driverPhone;
            $("#car_value").val(car);
        });
        this.$scope.saveCar = this.saveCar;
    }
    saveCar = () => {
        if (!$("#carForm").valid()) { return };
        this.operationService.getCarList("", null, this.$scope.carCodeBox, "", "", "", "", "", "", "", true, 0, 5).then((res) => {
            if (res.data.data.length == 0) {
                this.$ngBootbox.alert("车牌号非法,请重新填写");
            } else {
                this.operationService.updateCar(this.$scope.id, this.$scope.carIdBox, this.$scope.carCodeBox, this.$scope.driverNameBox, this.$scope.driverPhoneBox,
                    this.$scope.carLengthEnumBox, this.$scope.carTypeEnumBox, this.$scope.permitNumberBox, this.$scope.countrySubdivisionProvinceCode, this.$scope.countrySubdivisionCityCode, this.$scope.countrySubdivisionCountryCode, this.$scope.roadTransportCertificateNumberBox).then((res) => {
                        this.$ngBootbox.alert("修改成功");
                        $('#CarsAdd').modal('hide');
                        this.loadData();
                    });
            }
        });
    }

    /**
     * 自动填充承运商车辆信息
     */
    searchCar = (value: string) => {
        return this.carService.keywordlist(value, 0, 5).then((res) => {
            return res.data.data;
        });
    };

    carCodeSelect = (select: angucomplete<CarListItemResponse>) => {
        if (select) {
            this.$scope.carIdBox = select.description.id;
            this.$scope.carCodeBox = select.description.carCode;
            this.$scope.driverPhoneBox = select.description.driverPhone; //驾驶员号码
            this.$scope.driverNameBox = select.description.driver; //驾驶员名称
            this.operationService.getCarDetail(select.description.id).then((res) => {
                this.$scope.carLengthEnumBox = String(res.data.carLengthInt); // 车长
                this.$scope.carTypeEnumBox = String(res.data.carTypeInt); //   车型

                this.$scope.permitNumberBox = res.data.permitNumber;
                this.$scope.countrySubdivisionCode = res.data.countrySubdivisionCode;

                let countrySubdinvisionCode = this.$scope.countrySubdivisionCode;
                if (this.$scope.countrySubdivisionCode != undefined || this.$scope.countrySubdivisionCode != null) {
                    this.$scope.countrySubdivisionProvinceCode = countrySubdinvisionCode.substring(0, 2);
                    this.$scope.countrySubdivisionCityCode = countrySubdinvisionCode.substring(0, 4);
                    this.$scope.countrySubdivisionCountryCode = countrySubdinvisionCode.substring(0, 6);
                    this.getProvinceList();
                } else {
                    this.$scope.countrySubdivisionProvinceCode = "-1";
                    this.$scope.countrySubdivisionCityCode = "-1";
                    this.$scope.countrySubdivisionCountryCode = "-1";
                }

                this.$scope.roadTransportCertificateNumberBox = res.data.roadTransportCertificateNumber;

                if (!this.$scope.carLengthEnumBox || this.$scope.carLengthEnumBox == "0") {
                    this.$scope.carLengthEnumBox = "";
                }
                if (!this.$scope.carTypeEnumBox || this.$scope.carTypeEnumBox == "0") {
                    this.$scope.carTypeEnumBox = "";
                }
            });
        }
    };




    /**
     * 修改应付价格信息
     */
    receivalbleEdit = () => {
        //开户银行禁用
        this.$scope.openBankDis = true;

        if (!$('#ReceiptPrice').valid()) { return; }

        //测试开户银行是否有问题
        if (this.$scope.CData.advancePaymentList.length == 0) {
            this.$scope.advancePriceOne = ""
            this.$scope.advancePriceTypeOne = ""
            this.$scope.advancePriceTwo = ""
            this.$scope.advancePriceTypeTwo = ""
        } else {
            if (this.$scope.CData.advancePaymentList.length == 1) {
                this.$scope.advancePriceOne = this.$scope.CData.advancePaymentList[0].advancePrice
                this.$scope.advancePriceTypeOne = this.$scope.CData.advancePaymentList[0].advancePriceType
                this.$scope.advancePriceTwo = ""
                this.$scope.advancePriceTypeTwo = ""
            } else {
                this.$scope.advancePriceOne = this.$scope.CData.advancePaymentList[0].advancePrice
                this.$scope.advancePriceTypeOne = this.$scope.CData.advancePaymentList[0].advancePriceType
                this.$scope.advancePriceTwo = this.$scope.CData.advancePaymentList[1].advancePrice
                this.$scope.advancePriceTypeTwo = this.$scope.CData.advancePaymentList[1].advancePriceType
            }
        }

        this.$scope.payablePriceBox = this.$scope.CData.payablePrice;
        this.$scope.payableSummaryBox = this.$scope.CData.payableSummary;
        this.$scope.receiptPriceBox = this.$scope.CData.receiptPrice;
        $("#bankCode_value").val(this.$scope.CData.bankCode);
        this.$scope.bankCode = this.$scope.CData.bankCode;
        this.$scope.bankNameBox = this.$scope.CData.bankName;
        this.$scope.holderBox = this.$scope.CData.holder;
        this.$scope.payablePriceUnitEnumBox = this.$scope.CData.payablePriceUnitEnum;

        this.$scope.receiptPriceUnitEnumBox = this.$scope.CData.receiptPriceUnitEnum;
        let getPriceUnitList = this.valueService.getPriceUnitList().data;
        getPriceUnitList.splice(this.valueService.getPriceUnitList().data.length - 2, 1);
        this.$scope.priceUnitDropDown = getPriceUnitList;
        this.$scope.paymentMethodDropDown = this.valueService.getPaymentMethodList().data;

        //银行卡自动填充
        this.$scope.searchBank = this.searchBank;
        this.$scope.bankCodeSelect = this.bankCodeSelect;

        this.$scope.getBankName = this.commonService.debounce(this.getBankName, 500);
        this.$scope.saveReceivalble = this.saveReceivalble;

        $('#receiptPrice_bankNameBox').removeClass('error');
        $('#receiptPrice_holderBox').removeClass('error');

    }
    //保存 应付价格信息
    saveReceivalble = () => {
        if ($("#bankCode_value").val().length < 15 && $("#bankCode_value").val().length >= 0) {
            this.$ngBootbox.alert('请输入正确的银行卡');
            return;
        }
        //验证修改应付价格信息是否都填写好       
        if (!$('#ReceiptPrice').valid()) { return; }

        var AdvancePaymentList = [
            { advancePrice: Number(this.$scope.advancePriceOne), advancePriceType: this.$scope.advancePriceTypeOne },
            { advancePrice: Number(this.$scope.advancePriceTwo), advancePriceType: this.$scope.advancePriceTypeTwo }
        ];
        if (this.$scope.receiptPriceUnitEnumBox == null) {
            this.$scope.receiptPriceUnitEnumBox = "0";
        }
        this.operationService.updatePayable(this.$scope.id, this.$scope.payablePriceBox, this.$scope.payableSummaryBox, this.$scope.receiptPriceBox,
            $.trim($("#bankCode_value").val()), this.$scope.bankNameBox, this.$scope.holderBox, this.$scope.payablePriceUnitEnumBox, this.$scope.receiptPriceUnitEnumBox,
            AdvancePaymentList).then((res) => {
                this.$ngBootbox.alert("修改成功");
                $('#ReceiptPriceEdit').modal('hide');
                this.loadData();
            });
    }

    /**
     * 银行卡自动填充
     */
    searchBank = (value: string) => {
        return this.operationService.getBankList("", this.$scope.CData.carrierId, value, false, 0, 5).then((rel) => {
            return rel.data.data;
        });
    }

    bankCodeSelect = (select: angucomplete<BankListItemResponse>) => {
        if (select) {
            this.$scope.holderBox = select.description.holder;
            this.$scope.bankNameBox = select.description.bank;
            this.$scope.openBankDis = true;

        }
    }
    /**获取银行信息 */
    getBankName = () => {
        var bankLen = $("#bankCode_value").val().length;
        if (bankLen > 15) {
            this.operationService.BankInfo($("#bankCode_value").val()).then((res) => {
                if (res == null) {
                    res = undefined;
                    this.$scope.openBankDis = false;
                };
                this.$scope.bankNameBox = res.data.extData;
                this.$scope.openBankDis = true;

            }, (rej) => {
                this.$scope.openBankDis = false;
                return
            });
        }
    }


    /**
     * 修改合同信息
     */
    contractEdit = () => {
        this.$scope.contractNumDropDown = this.valueService.getGoodQuantityUnitList().data;
        this.$scope.oilStatusDropDown = this.valueService.getOilCCardStatusList().data;
        this.$scope.saveContract = this.saveContract;

        this.$scope.contractNumberT = this.$scope.contractData.contractNumber;
        this.$scope.quantityOfGoodsT = this.$scope.contractData.quantityOfGoods;
        this.$scope.goodsUnitEnumT = this.$scope.contractData.goodsUnitEnum;
        this.$scope.oilCardNumberT = this.$scope.contractData.oilCardNumber;
        this.$scope.oilCardStatusEnumT = this.$scope.contractData.oilCardStatusEnum;
        this.$scope.driverLicenseNumberT = this.$scope.contractData.driverLicenseNumber;
        this.$scope.frameNumberT = this.$scope.contractData.frameNumber;
        this.$scope.trailerNumberT = this.$scope.contractData.trailerNumber;
        this.$scope.engineNumberT = this.$scope.contractData.engineNumber;
        this.$scope.altermatePhoneT = this.$scope.contractData.altermatePhone;
        this.$scope.auxiliaryToolT = this.$scope.contractData.auxiliaryTool;
        this.$scope.trailerFrameNumberT = this.$scope.contractData.trailerFrameNumber;
        this.$scope.totalPriceT = this.$scope.contractData.totalPrice;

        //备注
        this.$scope.modalRemark = this.$scope.remark;
    }

    //保存合同信息
    saveContract = () => {
        this.operationService.updateContract(this.$scope.id, this.$scope.contractData.id, this.$scope.contractNumberT, this.$scope.quantityOfGoodsT,
            this.$scope.goodsUnitEnumT, this.$scope.oilCardNumberT, this.$scope.oilCardStatusEnumT, this.$scope.auxiliaryToolT, this.$scope.engineNumberT,
            this.$scope.frameNumberT, this.$scope.trailerNumberT, this.$scope.trailerFrameNumberT, this.$scope.driverLicenseNumberT,
            this.$scope.altermatePhoneT,this.$scope.totalPriceT,this.$scope.modalRemark).then((res) => {
                this.$ngBootbox.alert("修改成功");
                $("#ContractEdit").modal('hide');
                //get_allinfo(guid);
                this.loadData();
            });
    }


    /**
     * 修改承运商附件信息
     */
    attachmentEdit = () => {
        this.carAttachment();
        //保存附件信息
        this.$scope.saveAttachment = () => {
            var attachmentArr = [];
            this.uploaderList.forEach((itemA, indexA) => {
                if (itemA.attachmentTag == "") {
                    return;
                }
                else {
                    attachmentArr.push(["", itemA.attachmentName, itemA.attachmentPath, itemA.attachmentTag]);
                }
                //attachmentArr.push([itemA.attachmentId,itemA.attachmentName,itemA.attachmentPath,itemA.attachmentTag]);
            });
            this.operationService.updateAttachment(this.$scope.id, attachmentArr).then((res) => {
                this.$ngBootbox.alert("修改成功");
                $("#UploadFileEdit").modal('hide');
                this.loadData();

            });
        }

        /**
         * 取消修改附件
         */
        this.$scope.cancelSaveAttachment = () => {
            this.uploaderList = this.uploaderArr;
            this.$scope.attachList2.forEach(attach2=>{
                attach2.uploader.clearQueue()
            })
        }
    }


    /**
     * 修改承运单附件中的附件
     */
    carAttachment = () => {
        //清空附件
        $("input[type=file]").val("");
        this.$scope.attachList2. forEach(attach2=>{
            attach2.uploader.clearQueue()
        })
        let carArr2 = this.$scope.CData.carrierOrderAttachments;
        carArr2.forEach((item, index) => {
            this.$scope.attachList2[Number(item.attachmentTag)-1].uploader.addByAttach(item)
        });
    }

    /**
     * 选择上传文件后
     */
    onSuccessItem = (fileName: string, filePath: string, tag: number, file?: any) => {
        file.fileId = filePath;
        let attachment = {
            attachmentId: "",
            attachmentName: fileName,
            attachmentPath: filePath,
            attachmentTag: tag.toString()
        };
        this.uploaderList.push(attachment);
    }

    



}
angular.module("tms").controller("operationBreakBulkController", ["$scope", "operationService", "orderService", "$location", "$ngBootbox", "$state", "routeService", "feeService", "$http",
    "authorizationService", "valueService", "carrierService", "carService", "commonService", "$timeout", "areaService","ossUploaderService", IOperationController_breakBulk]);